package com.ap.core.webservice.managemerchant;

import javax.jws.WebParam;

import com.ap.core.cxf.jaxb.common.APCORE1FaultDetailsType;
import com.ap.core.cxf.jaxb.managemerchant.RequestMerchantRegistrationType;
import com.ap.core.cxf.jaxb.managemerchant.ResponseMerchantRegistrationType;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.info.OnBoardingResponseMessageInfo;
import com.ap.core.message.info.RequestMessageInfo;
import com.ap.core.message.service.CoreResponseInfo;
import com.ap.core.webservice.BaseWSService;
import com.core.ap.wsdl.managemerchantservice_1.ManageMerchant1PortType;
import com.core.ap.wsdl.managemerchantservice_1.RegisterMerchant1Fault;

/**
 * Implementation class for {@link com.core.ap.wsdl.managemerchantservice_1.ManageMerchant1PortType}
 */
public class ManageMerchantWebServiceImpl<AI> extends BaseWSService<RequestMessageInfo<?>,OnBoardingResponseMessageInfo,AI> implements ManageMerchant1PortType {

    @Override
    public ResponseMerchantRegistrationType registerMerchant1(@WebParam(partName = "registerMerchant_1Request", name = "registerMerchant_1Request", targetNamespace = "http://ap.core.com/xsd/managemerchantdata_1") RequestMerchantRegistrationType registerMerchant1Request) throws RegisterMerchant1Fault {
        CoreResponseInfo<OnBoardingResponseMessageInfo, AI> coreResponseInfo = null;
        LOG.info("Starting processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + registerMerchant1Request.getMsgHdr().getMsgType().name());
        try {        	
            coreResponseInfo = messageProcessor.process(registerMerchant1Request, new ResponseMerchantRegistrationType());            
	    } catch (BusinessFailureException e) {
	    	final APCORE1FaultDetailsType apcore1FaultDetailsType = buildSOAPFaultType(registerMerchant1Request.getMsgHdr().getMsgType().name(), registerMerchant1Request.getMsgHdr().getMsgId(), e);
        	throw new RegisterMerchant1Fault(getFaultString(registerMerchant1Request.getMsgHdr().getMsgType().name(), registerMerchant1Request.getMsgHdr().getMsgId()), apcore1FaultDetailsType);            
	    } catch (Exception e) {
	        LOG.error("Runtime exception occurred in ManageMerchant :", e);
	        final APCORE1FaultDetailsType apcore1FaultDetailsType = buildSOAPFaultType(registerMerchant1Request.getMsgHdr().getMsgType().name(), registerMerchant1Request.getMsgHdr().getMsgId(), e);
        	throw new RegisterMerchant1Fault(getFaultString(registerMerchant1Request.getMsgHdr().getMsgType().name(), registerMerchant1Request.getMsgHdr().getMsgId()), apcore1FaultDetailsType);            
	    }
        LOG.info("Finishing processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + registerMerchant1Request.getMsgHdr().getMsgType().name());
        return (ResponseMerchantRegistrationType)coreResponseInfo.getResponse();
    }
}
